﻿using System;
using System.Windows.Forms;
using Com.Seezt.Skins;
using Components.Enum;
using UI.StorageManagement;

namespace UI.BuyManagement
{
    public partial class FrmAcceptList : UI.ParentForm.BaseMain
    {
        FrmAcceptEdit edit = null;
        ToolStripButton tspPrint = null;

        private string _orderId;

        public FrmAcceptList(string modulecode, string action)
            : base(modulecode, action)
        {
            InitializeComponent();

            tspAdd.Visible = false;

            PageInit();
        }

        public FrmAcceptList(string modulecode, string action, string orderId)
            : this(modulecode, action)
        {
            _orderId = orderId;
        }

        private void PageInit()
        {
            tspPrint = new ToolStripButton();
            tspPrint.Tag = "P";
            tspPrint.Text = "打 印";
            tspPrint.Click += tspPrintClick;
            tspTop.Items.Add(tspPrint);

            this.ControlBox = true;
            this.Size = this.MaxWindow;
            this.Text = "收货单列表";
            this.IsQueryComponent = true;
        }

        private void tspPrintClick(object sender, EventArgs e)
        {
            DataGridViewRow row = this.GetSelectedRow();
            if (null == row) return;

            var print = new FrmBuy3a00Print();

            print.AddParam("listid", Components.Validation.ToString(row.Cells["listid"].Value)); //添加参数
            print.Show();
        }

        protected override void OnViewClick(ToolStripButton btn, DataGridViewRow row)
        {
            if (null == row) return;

            edit = new FrmAcceptEdit(this.ModuleCode, "V", Components.Validation.ToString(row.Cells["listid"].Value));
            edit.ShowDialog();
        }

        protected override void UpdatePager(UI.Common.Pager pager)
        {
            pager.FilterAppName = "a.usercode";

            var where = string.Format(" a.doctype = '{0}' ", DocumentType.PurchaseAccept);

            if (!string.IsNullOrEmpty(_orderId))
                where += string.Format(" and a.refid='{0}' ", _orderId);

            pager.StrWhere = where;
        }
    }
}
